package servlet;



import bean.SupplierBean;
import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class SupplieraddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int sid =Integer.parseInt(request.getParameter("sid"));
        String name =request.getParameter("name");
        String person =request.getParameter("person");
        String tel =request.getParameter("tel");
        String address =request.getParameter("address");
        String email =request.getParameter("email");

        String sql ="INSERT INTO supplier VALUES (?,?,?,?,?,?)";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
            ps.setInt(1, sid);
            ps.setString(2, name);
            ps.setString(3, person);
            ps.setString(4, tel);
            ps.setString(5, email);
            ps.setString(6, address);
            int up = ps.executeUpdate();
            if(up==1){
                request.getRequestDispatcher("supplier.jsp").forward(request, response);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}
